var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var user = require('../../services/user.js');
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    show: false,
    wechatPoup: false,
    serverPoup: false,
    
  },
  /**登陆 */
  goLogin() {
    //检测登录状态 身份为游客
    if (this.data.userInfo.id != 'temp') {
      wx.showToast({
        title: '已经登录',
        icon: 'none'
      });
    } else {
      wx.navigateTo({
        url: "../authorize/authorize"
      })
    }

  },
  // 跳转到二维码
  codeScan:function(){
    wx.navigateTo({
      url: '../../myPages/codeScan/codeScan'
    })
  },
  bindGetUserInfo(e) {
    console.log(e.detail.userInfo);
    this.goLogin();
  },
  // 添加offer
  goAddOffer(e) {
    wx.navigateTo({
      url: '../../pages/sendOffer/sendOffer'
    })
  },
  // 添加面经
  goWriteExp(e) {
    wx.navigateTo({
      url: '../../pages/writeEXP/writeEXP'
    })
  },
  // 跳转创作中心
  goCreatCenter(e){
    wx.navigateTo({
      url: '../../pages/createCenter/createCenter'
    })
  },
  // 跳转消息中心
  goInfosCenter(e) {
    wx.navigateTo({
      url: '../../pages/infosCenter/infosCenter'
    })
  },
  /*跳转个人信息编辑*/
  goUserInfo(e) {
    if (e.currentTarget.dataset.userid != undefined && e.currentTarget.dataset.userid != 'temp') {
      wx.navigateTo({
        url: '../../myPages/userInfo/userInfo?userid=' + e.currentTarget.dataset.userid
      })
    } else {
      this.goLogin();
    }
  },
  /*跳转心愿单*/
  goToWish(e) {
    wx.showToast({
      icon:'none',
      title: "该功能暂时未上线",
      duration: 2000,
    })
    // if (e.currentTarget.dataset.userid != undefined && e.currentTarget.dataset.userid != 'temp') {
    //   wx.navigateTo({
    //     url: '../../myPages/wish/wish?userid=' + e.currentTarget.dataset.userid
    //   })
    // } else {
    //   wx.showToast({
    //     title: '请先登录',
    //     icon: 'none'
    //   });
    // }
  },
  /*跳转导师个人中心 */
  goToTeacherCenter(e) {
    if (e.currentTarget.dataset.teacherid != undefined && e.currentTarget.dataset.teacherid != 'temp') {
      wx.navigateTo({
        url: '../../myPages/teacherCenter/teacherCenter?teacherid=' + e.currentTarget.dataset.teacherid
      })
    } else {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      });
    }
  },
  /**我约的导师 */
  goToOrderTheacher(e) {
    if (e.currentTarget.dataset.userid != undefined && e.currentTarget.dataset.userid != 'temp') {
      wx.navigateTo({
        url: '../../myPages/orderTeacher/orderTeacher?userid=' + e.currentTarget.dataset.userid
      })
    } else {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      });
    }
  },
  /**我约的学员 */
  goToOrderStudent(e) {
    if (e.currentTarget.dataset.userid != undefined && e.currentTarget.dataset.userid != 'temp') {
      wx.navigateTo({
        url: '../../myPages/orderStudent/orderStudent?userid=' + e.currentTarget.dataset.userid
      })
    } else {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      });
    }
  },

  /**客服反馈 */
  gotoCustomerService() {
    // wx.navigateTo({
    //   url: '../../myPages/customerService/customerService'
    // })
    this.setData({
      show: true,
      serverPoup: true,
      wechatPoup: false,
    })
  },
  /*跳转新手帮助*/
  gotoHelp() {
    wx.navigateTo({
      url: '../../myPages/help/help'
    })
  },
  /*我问的  用户*/
  goUserReply() {
    wx.navigateTo({
      url: '../../myPages/Replylists/Replylists'
    })
  },
  // 我答的  导师
  goReplylists() {
    wx.navigateTo({
      url: '../../myPages/techerReLists/techerReLists'
    })
  },
  /**打开关注公众号 */
  showFocusWechat() {
    this.setData({
      show: true,
      wechatPoup: true,
      serverPoup: false,
    })
  },
  /*关闭弹框*/
  onClose() {
    this.setData({
      show: false,
      wechatPoup: false,
      serverPoup: false
    })
  },
  // 关闭提问码
  onCodeClose() {

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let userInfo = wx.getStorageSync('userInfo');
    console.log(userInfo);
    // 页面显示 
    //登录用户
    if (userInfo && userInfo.id) {
      this.setData({
        userInfo: userInfo,
      });
    } else {
      // 游客身份 
      this.setData({
        userInfo: app.globalData.userInfo,
      });
    }
    wx.hideShareMenu();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})